package indi.kider.server.applet.service;

import indi.kider.common.constant.AppUserType;
import indi.kider.common.model.apartment.RentLock;
import indi.kider.server.apabus.mapper.RentMapper;
import indi.kider.server.apartment.mapper.DevLockMapper;
import indi.kider.server.applet.model.User;
import indi.kider.server.employee.mapper.DevSensetimeUploadMapper;
import indi.kider.server.employee.mapper.TenantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@SuppressWarnings("ALL")
public class RentLockServiceImpl implements RentLockService {

    @Autowired
    private DevLockMapper devLockMapper;
    @Autowired
    private RentMapper rentMapper;
    @Autowired
    private DevSensetimeUploadMapper devSensetimeUploadMapper;
    @Autowired
    private TenantMapper tenantMapper;

    @Override
    public List<RentLock> appletGetRentLock(RentLock rentLock,User user) throws Exception {
        //租客
        if(AppUserType.TENANT == user.getType() || AppUserType.FRIEND == user.getType()){
            rentLock.setTenantId(user.getId());
//            Tenant tenant = tenantMapper.selectByPrimaryKey(user.getId());
//            Example rentE = new Example(Rent.class);
//            // 去掉日期限制
//            rentE.createCriteria().andEqualTo("tenantId",user.getId()).andEqualTo("state",1);//.andGreaterThan("rentDate","2018-08-23");
//            List<Rent> rentList = rentMapper.selectByExample(rentE);
//            if(tenant != null && tenant.getCardId() != null && rentList != null && !rentList.isEmpty()){
//                DevSensetimeUpload devSensetimeUpload = new DevSensetimeUpload();
//                devSensetimeUpload.setId_number(tenant.getCardId());
//                devSensetimeUpload.setState(1);
//                List<DevSensetimeUpload> devSensetimeUploadList = devSensetimeUploadMapper.select(devSensetimeUpload);
//                if(devSensetimeUploadList == null || devSensetimeUploadList.isEmpty()){
//                    throw new Exception("您未进行人证验证请在一体机上验证");
//                }
//            }
            //房東
        }else if(AppUserType.LANDLORD == user.getType()){
            throw new Exception("暂不支持房东登陆");
            //工人
        }else if(AppUserType.WORKER == user.getType()){
            rentLock.setWorkdId(user.getId());
            //服务人员
        }else if(AppUserType.WAITER == user.getType()){
            rentLock.setWaiterId(user.getId());
            //合作企業
        }else if(AppUserType.COOPERATE == user.getType()){
            rentLock.setEmployeeId(user.getId());
        }
        rentLock.setPhone(user.getPhone());
        //默認為未發佈房源
        if(rentLock.getReleaseState() == null){
            rentLock.setReleaseState("1");
        }
        List<RentLock> s = devLockMapper.appletGetRentLock(rentLock);
        return s;
    }
}
